home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
- From: thay@uoguelph.ca (Toby K Hay)
- Newsgroups: comp.lang.c
- Subject: Re: RAND_MAX
- Date: 1 Apr 1996 14:41:58 GMT
- Organization: University of Guelph
- Message-ID: <4jopvm$9sm@ccshst05.cs.uoguelph.ca>
- References: <4jnr55$e6l@skivs.ski.org>
- NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- Gemini Thunder (gt@ns.oon.or.jp) wrote:
- : K&R2 says:
- : "rand returns a a pseudo-random integer in the range 0 to RAND_MAX,
- : which is at least 32767"
-
- : It looks like RAND_MAX is not required to be the same as any other
- : limit (such as MAX_INT, etc.), that is fine, but why?
- : Wouldn't it be easier if RAND_MAX == MAX_INT or some other value?
-
- : The reason I say this is how can you be sure your array will hold a
- : RAND_MAX sized integer, without some checking before hand, if RAND_MAX
- : is out there doing its own thing?
-
- I wrote and debugged a program on my PC using TurboC with its 16 bit
- integers and then moved it to an SGI with 32 bit integers, assuming that
- RAND_MAX would be much larger. I was suprised to find that in fact it
- was the same on the two systems, and I had to rewrite some code to get
- random numbers of 31 bits.
- Since rand() returns an integer you can be sure that if your array is
- of type integer it will hold the value returned by rand(). Was that the
- question?
- Toby Hay thay@uoguelph.ca
-